module.exports = app => {
    const { STRING, INTEGER, DATE } = app.Sequelize;
    var User = require('../model/user')
    const Post = app.model.define('post', {
        id: {
          type: INTEGER(20),
          primaryKey: true,
          autoIncrement: true
        },
        user_id: {
          type: INTEGER(20),
          allowNull: false,
          defaultValue: 0,
          comment: '发布人ID',
        },
        title: {
          type: STRING(60),
          allowNull: false,
          defaultValue: '',
          comment: '帖子标题',
        },
        content:{
          type:STRING(800),
          allowNull: false,
          defaultValue: '',
          comment: '帖子文字内容'
        },
        post_type:{
          type:INTEGER(2),
          allowNull: false,
          defaultValue: 0,
          comment: '帖子类型'
        },
        topic:{
            type:INTEGER(2),
            allowNull: false,
            defaultValue: 0,
            comment: '话题类型'
        },
        price:{
            type:INTEGER(3),
            allowNull: false,
            defaultValue: 0,
            comment: '云领养价格'
        },
        titleImg:{
          type:STRING(255),
          defaultValue: '',
          comment: '标题图片'
        },
        animalId:{
          type:INTEGER(20),
          defaultValue: '2',
          comment: '与帖子相关的动物的id'
        },
        shareNum:{
          type:INTEGER(11),
          allowNull: false,
          defaultValue: 0,
          comment: '分享数量'
        },
        imgList:{
          type:STRING(1000),
          defaultValue: '',
          comment: '图片列表'
        },
        created_time: {
          type:DATE
        },
        updated_time: DATE,
      });
      Post.associate = function () {
        // 关联用户
        Post.belongsTo(app.model.User, {as:'pos', foreignKey:'user_id', targetKey:'id'});
    }
    return Post;
}